package self.learn.record.proxy;

import org.junit.Test;
import org.springframework.cglib.core.DebuggingClassWriter;
import self.learn.record.proxy.cglib.MatchmakerCglibProxy;
import self.learn.record.proxy.jdk.MatchmakerJdkProxy;
import self.learn.record.proxy.static_.Family;
import self.learn.record.proxy.static_.Matchmaker;
import self.learn.record.proxy.static_.ZhangFamily;

/**
 *
 * @author Mercy Yang
 * @date 2017/10/21
 */
public class ProxyTest {
    public static void main(String[] args) {
        Matchmaker matchmaker = new Matchmaker(new ZhangFamily());
        matchmaker.allianceWith();
    }

    @Test
    public void testJdkDynamicProxy()throws Exception{
        // 将此属性设置为true，将动态生成的代理class文件保存到本地
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");

        Family family = new MatchmakerJdkProxy(new ZhangFamily()).getProxy();
        family.allianceWith();
    }


    @Test
    public void testCglibDynamicProxy()throws Exception{
        // 将此属性设置为true，将动态生成的代理class文件保存到本地
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,"D:\\dev\\dynamic-proxy\\");
        Family family = new MatchmakerCglibProxy().getProxy();
        family.allianceWith();

    }
}
